#!/usr/bin/env python
# -*- coding: utf-8 -*-

import time
from multiprocessing import Manager, Pool

def read(q):
    while True:
        if not q.empty():
            print('read %s'%q.get())
        time.sleep(0.5)

def write(q):
    for i in range(20):
        while q.full():
            print('queue is full...')
            time.sleep(0.1)
        q.put('msg-%d'%i)
        print('write msg-%d'%i)

if __name__ == "__main__":
    po = Pool(5)
    q = Manager().Queue(5)
    po.apply_async(write, args=(q,))
    po.apply_async(read, args=(q,))
    po.close()
    po.join()
    print("done.")


